package main

import (
	"net"
	"github.com/name5566/leaf/log"
	"wind/wind-config"
)

func main() {
	wind_config.ConfigServer("wind-config/server.json")

	listener, err := net.ListenUDP("udp", &net.UDPAddr{
		IP: net.ParseIP(wind_config.ServerConfig.ServerHost),
		Port: wind_config.ServerConfig.ServerPort,
	})
	if err != nil {
		log.Fatal("%s", err)
		return
	}
	log.Debug("Local: <%s> \n", listener.LocalAddr().String())
	data := make([]byte, 1024)
	for {
		n, remoteAddr, err := listener.ReadFromUDP(data)
		if err != nil {
			log.Fatal("error during read: %s", err)
		}
		log.Debug("<%s> %s\n", remoteAddr, data[:n])
		_, err = listener.WriteToUDP(data[:n], remoteAddr)
		if err != nil {
			log.Error("Write To Client %s", err.Error())
		}
	}
}
